<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目到账提款管理列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
         <div class="fieldBox col_50">
                    <div class="label">项目名称</div>
                <div class="field">
                    <input name="fncprjnm" id="fncprjnm" type="text" class="ui-textbox" value="${fncprjnm}" >
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox col_50">
                <div class="label">金融机构</div>
                <div class="field">
                    <input name="fncinsid" id="fncinsid" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
                </div>
             </div>
               
         </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" onclick="searchBtn();"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
               
               
            </div>

			
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div> 
</div>

<script type="text/javascript">
	var grid = null;
	var queryFlag ="${queryFlag}"; //只查询列表
	$(function () {
		initcombobox();
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbuss/fnovercollinfo/initList.do',
	    	method : 'get',	 
	    	
	        columns: [
                 { display: '状态', name: 'showColor', width: 60 , align:'center', 
    	            	render: function (rowdata, rowindex, value, column) { 
   	                	var imgpath = '<%=path%>/resource/lib/images/';
   	                	if(rowdata.showColor =="green"){
   	                		imgpath += 'greenpoticon.png';
   	                	}else if(rowdata.showColor =="yellow"){
   	                		imgpath += 'goldenpoticon.png';
   	                	}else if(rowdata.showColor =="red"){
   	                		imgpath += 'redpoticon.png';
   	                	}
   		                return '<img alt="" width="20px" height="20px" src="'+imgpath+'">';
               	}},       
	            { display: '退回状态', name: 'transSt', minWidth: 140 ,enabledSort:true,
	            	  render: function (rowdata, rowindex, value, column) { 
	            		if(value=="1"){
	            			  return "已退回";
	            		  } else if(value==2){
	            			  return "部分退回"
	            		  }else{
	            			  return "未退回"
	            		  }
	            	  }
	            
	            }, 
	            
	            
	            { display: '融资机构', name: 'fncInsNm', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '融资报价', name: 'fncScmNm', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '项目编号', name: 'fncPrjId', minWidth: 140 , 
                        render: function (rowdata, rowindex, value, column) { 
	            		
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.prjId+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
	            		},
	            	enabledSort:true}, 
	          

	            { display: '项目名称', name: 'fncPrjNm', minWidth: 140 , enabledSort:true}, 
	            { display: '期次', name: 'payPd', minWidth: 140 , enabledSort:true}, 
	            { display: '超额抵押', name: 'paidUpAmt', minWidth: 140 ,
	            	 render: function (rowdata, rowindex, value, column) { 
		            		
		            		var h = '';
		            			if(value&&value!="null"){
		            		    h+=fmoney(value/100.00, 2);
		            			}else{
		            				h+=0.00;
		            			}
		                        return h;
		            		},
	            	
	            	enabledSort:true}, 
	            { display: '剩余金额', name: 'surplusMoney', minWidth: 140 ,
	            		 render: function (rowdata, rowindex, value, column) { 
		            		var h = '';
		            			if(value&&value!="null"){
		            		    	h += fmoney(value/100.00, 2);
		            			}else{
		            				h+=0.00;
		            			}
		                        return h;
		            	 }, 
			      }, 
	            { display: '归集日期', name: 'gthrDt', minWidth: 140 , enabledSort:true,render:renderDate},          
		        { display: '还款日期', name: 'payDt', minWidth: 140 , enabledSort:true,render:renderDate}, 
		        { display: '计划退回时间', name: 'reReturnTm', width: 150, render:renderDate},
 
	            getOptColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    
	
	
	});
	
	//获取操作列
	function getOptColumn(){
		if(queryFlag!="query"){
		var column = {
                display: '操作',
                isSort: false,
                width: 200,
                align:'left',
                render: function (rowdata, rowindex, value){
                	 	var h="";
		            	h+='<a class="sq-button-hasicon" href="javascript:view(';
		            	h+="'"+rowdata.id+"',";
		                h+=")\"><i class='sqBtnIco_4'></i>查看</a>";
           				console.log(rowdata);
		                if(rowdata.foSt!=1){//可以多次发起退回申请
			                if(rowdata.transSt!=1){
			                    h+='<a class="sq-button-hasicon" href="javascript:addBtn(';
			                    h+="'"+rowdata.id+"'";
			                    h+=')"><i class="sqBtnIco_4"></i>申请退回</a>'
			                	
			                }
		                }
                    return h;
                }
            }
		return column;
		}else{
			var column =  {};
			return column;
		}
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function addBtn(id){
		var callback = function(){
			 grid.reload();
		}
		Add_navTab('FNC_OVER_COLL_INFO_ADD_'+id,'超额抵押确认到账信息','<%=path%>/rfbuss/fnovercollinfo/toAddPage.do?id='+id,callback);
		
	}
	
	function searchBtn(){

        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	function modifyBtn(id){
		var callback = function(){
			 grid.reload();
		}
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		} */
		var fromPrjFlag = true;
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		//查询参数
		var detailFlag = false;
	//	var params = "?fromPrjFlag="+fromPrjFlag+"&id="+id+"&detailFlag="+detailFlag;
	var params="?id="+id;
		//如果客户ID存在则加入参数

		//var id = selectedRows[0].id;
		Add_navTab('fnc_prj_bsc_info_trans_add'+id,'再融资项目确认到账信息','<%=path%>/rfbuss/fncprjbscinfo/toAddPage.do'+params,callback);
	}
	
	function detailBtn(id){

		
		Add_navTab('tab_project_detail'+id,'项目基本信息详情','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage.do?id='+id);
	}
	//启动流程
	function flowStart(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var modelTyp = "R004";
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		var _id = selectedRows[0].id;
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			id:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/rfbuss/fncprjbscinfo/addFlowStart.do',
            		success:function(msg){
            			wait_dialog.close();
            			 if(msg.success == 1){
           					 UIUtils.alertSuccessHold1(msg.info);
            				 grid.reload();
            			 }else{
           					 UIUtils.alertErrorHold1(msg.info);
            			 }
            		}
            	});
            }
        });
	}
	
	
	
	
	
 
  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				"fncprjnm":"",
				"fncinsid":""
			 });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    }
	}
	
	function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
	var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		  var combobox=  $("#fncinsid").ligerComboBox({
	    	     data:frilist,
	             selectBoxWidth: 270,
	             selectBoxHeight: 150,
	             valueField: "id",
	             textField: "fundRasInsNm",
	             autocomplete: function (e){
	                 filter_autoComboboxData(e.key, this);
	                 e.show();
	             }
	           });
	 }
	
	 
	
		function view(id){
			//var timestamp=new Date().getTime();
			var param = '<%=path%>/rfbuss/fnovercollinfo/view.do?id=' + id;
			Add_navTab('fnovercollinfoView'+id,'详情',param, function () {
				//grid.reload();
			});
		}
	
</script>

</body>
</html>